<template>
  <div class="page" style="">
    <div class="print_title">{{ formData.trainingType == 'apply' ? '培训申请详情' : formData.trainingType == 'change' ?
      '变更培训申请详情' : '作废培训申请详情' }} · 禾美环保</div>
    <p class="title">基本信息</p>
    <a-row type="flex" justify="start" class="content" style="padding: 0 9px;">
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">单据编号:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.billNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请人:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createBy_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>

      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请部门:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.applyDeptId_dictText ?
              formData.applyDeptId_dictText : formData.applyDeptId }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请时间:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.createTime }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">申请人所属团队:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.costTeamId_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12" v-if="formData.trainingType == 'change'">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">选择培训档案:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.finalNo }}</p>
          </a-col>
        </a-row>
      </a-col>
      <template v-if="formData.trainingType == 'cancel'">
        <a-divider>作废信息</a-divider>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap">选择培训档案:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.finalNo }}</p>
            </a-col>
          </a-row>
        </a-col>
        <!-- <a-col :span="12">
          <a-row>
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap">申请人:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationProposer_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>

        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap">申请部门:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationDepartId_dictText }}</p>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="12">
          <a-row style="margin-bottom: 0">
            <a-col style="display: flex;">
              <p style="margin-bottom: 0; white-space: nowrap">申请时间:</p>
              <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidationCreateTime }}</p>
            </a-col>
          </a-row>
        </a-col> -->
      </template>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训分类:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingCategory_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训目的:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingObjective }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训地点:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingAddress }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">获得证书名称:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.certificateName }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训开始日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingStartDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训结束日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingEndDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">服务开始日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.serviceStartDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训服务期限:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingServiceLimit_dictText }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">服务结束日期:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.serviceEndDate }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训费用(元/人):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingFee }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="12">
        <a-row style="margin-bottom: 0">
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">培训费用合计(元):</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.trainingFeeTotal }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col :span="24">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">备注:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.remark }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col style="display: flex;" v-if="formData.trainingType == 'change'">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">变更描述:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.changeRemark }}</p>
          </a-col>
        </a-row>
      </a-col>
      <a-col style="display: flex;" v-if="formData.trainingType == 'cancel'">
        <a-row>
          <a-col style="display: flex;">
            <p style="margin-bottom: 0; white-space: nowrap">作废描述:</p>
            <p style="margin:0 0 0 6px; word-break: break-all;">{{ formData.invalidRemark }}</p>
          </a-col>
        </a-row>
      </a-col>
    </a-row>

    <a-row type="flex" justify="center">
      <a-col>
        <p class="title_table">培训人员</p>
      </a-col>
      <a-col :span="24">
        <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false" size="small"
          :rowClassName="tableRowClass"></a-table>
      </a-col>
    </a-row>

    <!-- 附件信息 -->
    <FileInfor :purchaseFile="purchaseFile" title="附件信息" v-if="purchaseFile && purchaseFile.length"></FileInfor>
    <!-- 流程详情 -->
    <ProcessInfor v-if="formData.bpmStatus !== '1'" :dataHistorySource="dataHistorySource"></ProcessInfor>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
import FileInfor from '@/components/print/FileInfor.vue' // 审批历史流程列表组件
import ProcessInfor from '@/components/print/ProcessInfor.vue' // 审批历史流程列表组件
import ProcessInforOriginal from '@/components/print/ProcessInforOriginal.vue' // 原单据审批历史流程列表组件
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
export default {
	props: {
		formData: {
			type: Object,
			default: () => {},
			required: true
    },
		formDataHistory: {
			type: Object,
			default: () => {},
			required: true
    }
	},
  components: {
    FileInfor,
    ProcessInfor,
    ProcessInforOriginal
  },
  data() {
    return {
      filterMultiDictText,
      dictOptions: {},
      dataSource: [], // 物料列表
      columns: [
				{
					title: '序号',
					dataIndex: '',
					key: 'rowIndex',
					width: 45,
					align: 'center',
					customRender: function (t, r, index) {
						return parseInt(index) + 1;
					}
				},
				{
          title: '姓名',
					align: 'center',
          dataIndex: 'employeeId_dictText'
				},
				{
          title: '所属部门',
					align: 'center',
          dataIndex: 'departId_dictText'
				},
        {
          title: '联系方式',
					align: 'center',
          dataIndex: 'linkTel'
				}
			],
			dataHistorySource: [], // 流程列表
      dataOriginalHistorySource: [], // 原单据流程列表
			url: {
        list: '/api/erp/hr/training/erpHrTrainingDetail/allList',
				historyList: '/api/erpmng/act/task/processHistoryList' // 流程历史跟踪接口
			},
			purchaseFile: [] // 附件
    };
  },
	watch: {
		formData: {
			handler (val) {
				if (val) {
					this.list()
					this.getHistoryList()
          this.initDictConfig() // 字典值
          if (val.attachment) {
            this.purchaseFile = val.attachment.split(',')
					}
				}
			},
			immediate: true
		},
		formDataHistory: {
			handler (val) {
				if (val) {
					this.getHistoryList()
				}
			},
			immediate: true
		}
	},
	methods: {
		// 获取列表
		getHistoryList() {
			var params = { processInstanceId: this.formDataHistory.procInsId };// 查询条件
			getAction(this.url.historyList, params).then(res => {
				if (res.success) {
					this.dataHistorySource = res.result.records || res.result
				}
			})
		},
    initDictConfig() {
      initDictOptions('erp_omc_team_manager,alias_name,id').then(async (res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'costTeamId', res.result)
        }
      })
      initDictOptions('training_category').then(async (res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'trainingCategory', res.result)
        }
      })
    },

		list () {
			if (!this.formData.id) {
				return false
			}
			var params = {
				billId: this.formData.id,
        pageSize: -1,
        pageNo: 1,
        column: 'createTime',
        order: 'asc'
			}
			getAction(this.url.list, params).then(res => {
				if (res.success) {
						this.dataSource = res.result.records || res.result
						this.dataSource.forEach((item, index) => {
						item.key = index
					})
				}
      })
		},

		tableRowClass(record, index) {
			if (index == 0) {
				return 'rowClass';
			}
      return ''
    }
	}
};
</script>
<style lang="less" scoped>
.page{
	background: #ffffff;
	padding: 19px 28px 0 28px;
	width: 750px;
	.print_title{
		font-size: 15px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 9px;
	}
	.title {
		background: #EEEEEE;
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
		padding: 11px 9px;
	}
	.title_table{
		font-size: 13px;
		font-family: Alibaba PuHuiTi 2.0;
		font-weight: normal;
		color: #000000;
	}
}
/deep/ .rowClass{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead th{
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-thead tr{
	background: #EEEEEE;
}
/deep/ .ant-table-small > .ant-table-content > .ant-table-body {
    margin: 0 0px;
}
/deep/ .ant-table-body tr {
	font-size: 10px;
	font-family: Alibaba PuHuiTi 2.0;
	font-weight: normal;
	color: #000000;
}
/deep/ .ant-table-body tr td {
    word-wrap:break-word;
    word-break:break-all;
  }
  .content{
  font-size: 13px;
}
</style>
